package cn.car.controller;

import cn.car.biz.VehicleEntryExitInfoBiz;
import cn.car.domains.vo.Result;
import cn.car.domains.vo.vehicleEntryExit.CreateEntryExitInfoReq;
import cn.car.domains.vo.vehicleEntryExit.UpdateVehicleEntryExitReq;
import cn.car.domains.vo.vehicleEntryExit.VehicleEntryExitInfoRes;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vehicleEntryExit")
@Tag(name = "Vehicle Entry/Exit", description = "车辆出入信息管理接口")
public class VehicleEntryExitInfoController {

    @Resource
    private VehicleEntryExitInfoBiz vehicleEntryExitInfoBiz;

    /**
     * 创建车辆信息
     *
     * @param req 创建车辆请求参数
     */
    @PostMapping("/create")
    @Operation(summary = "创建车辆信息", description = "创建车辆信息接口：根据请求参数创建一条车辆出入信息")
    public Result<Void> createVehicle(@RequestBody CreateEntryExitInfoReq req) {
        vehicleEntryExitInfoBiz.createVehicle(req);
        return Result.success();
    }


    /**
     * 根据车牌号获取车辆信息
     *
     * @param vehicleNumber 车牌号
     */
    @PostMapping("/getByNumber")
    @Operation(summary = "根据车牌号查询车辆信息", description = "通过车牌号精确查询车辆出入信息")
    public Result<VehicleEntryExitInfoRes> getVehicleByNumber(@Parameter(name = "vehicleNumber", description = "车牌号", required = true) @RequestParam String vehicleNumber) {
        return Result.success(vehicleEntryExitInfoBiz.getVehicleByNumber(vehicleNumber));
    }

    /**
     * 更新车辆信息
     *
     * @param req 更新车辆请求参数
     */
    @PostMapping("/update")
    @Operation(summary = "更新车辆信息", description = "更新车辆信息接口：根据请求参数更新车辆出入信息")
    public Result<Void> updateVehicle(@RequestBody UpdateVehicleEntryExitReq req) {
        vehicleEntryExitInfoBiz.updateVehicle(req);
        return Result.success();
    }

    /**
     * 删除车辆信息
     * @param id 车辆ID
     */
    @PostMapping("/delete")
    @Operation(summary = "删除车辆信息", description = "根据车辆ID删除车辆出入信息")
    public Result<Void> deleteVehicle(@Parameter(name = "id", description = "车辆ID", required = true) @RequestParam Long id) {
        vehicleEntryExitInfoBiz.deleteVehicle(id);
        return Result.success();
    }
}
